The "raw data" of this analysis comes from third parties and must be downloaded from the ANES, Afrobarometer and Harvard Dataverse. See more in 3(2) and 5 below.

For replication of Wasow, Omar, 2025, "Text as Behavior." 

Note: all code requires data in "Original Format" not "Archival Format (.tab)"

1. Using application RStudio, open text_replication.Rproj

2. Install package "here" to manage paths to project's files.
   - install.packages("here")
   - library(here)
   - to see other needed packages, open text_rep/text_code/text_packages.R

3. There are two ways to replicate the analysis: 
   - (1) Use pre-processed data in folder text_rep/text_data_output
   - (2) Download original third party datasets (ANES, Afrobarometer, KMM/Social Exclusion), put them in folder text_rep/text_data_raw, and run processing scripts which create processed data in the folder text_rep/text_data_output

4. If using pre-processed data, confirm that the folder text_data_output has the following files:
  - aap_processed.Rdata
  - afrobarometer_processed.Rdata
  — anes2016_processed.Rdata
  — anes2016_tidy_text.Rdata
  — anes2020_merged.Rdata
  — anes2024_merged.Rdata

4a. Then render the pdf by opening "text_as_behavior9_rep.Rmd" and selecting "Knit" within RStudio or running the following command:

rmarkdown::render(
    input         = here::here("text_docs", "text_as_behavior9_rep.Rmd"),
    output_format = "pdf_document",
    output_dir    = here::here("text_docs"),
    clean         = FALSE
)

5. If downloading the original third party datasets, make sure the folder text_rep/text_data_raw has the following files at the paths listed below:

# ANES Files
  - anes_timeseries_2016_rawdata.txt
  - anes_timeseries_2016_redacted_openends.xlsx
  - anes_timeseries_2016_voteval.csv
  - anes_timeseries_2020_stata_20220210.dta
  - anes_timeseries_2020_redactedopenends_excel_20211118.xlsx
  - anes_timeseries_2024_spss_20250808.sav
  - anes_timeseries_2024_redactedopenends_excel_20250923.xlsx

## 2016
From: https://electionstudies.org/data-center/2016-time-series-study/
Paths:
  - text_rep/text_data_raw/ANES/anes_timeseries_2016_rawdata.txt
  - text_rep/text_data_raw/ANES/anes_timeseries_2016_redacted_openends.xlsx
  - text_rep/text_data_raw/ANES/anes_timeseries_2016_voteval.csv


## 2020
From: https://electionstudies.org/data-center/2020-time-series-study/
Paths:
  - text_rep/text_data_raw/ANES/anes_timeseries_2020_stata_20220210.dta"
  - text_rep/text_data_raw/ANES/anes_timeseries_2020_redactedopenends_excel_20211118.xlsx
  - text_rep/text_data_raw/ANES/anes_timeseries_2020_csv_VoterValidation.csv


## 2024
From: https://electionstudies.org/data-center/2024-time-series-study/
Paths:
  - text_rep/text_data_raw/ANES/anes_timeseries_2024_spss_20250808.sav
  - /text_rep/text_data_raw/ANES/anes_timeseries_2024_redactedopenends_excel_20250923.xlsx


## AFROBAROMETER
File:
  - merged_r6_data_2016_36countries2.sav
From: 
  - https://www.afrobarometer.org/survey-resource/merged-round-6-data-36-countries-2016/
Path: 
  - text_rep/text_data_raw/Afrobarometer/merged_r6_data_2016_36countries2.sav


## KMM/Social Exclusion 
File: 
  - experimentaldata_kmm_050916_final.dta
From: 
  - https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/GMWOY6
Path:
  - text_rep/text_data_raw/experimentaldata_kmm_050916_final.dta


5a. Open make_script.R and run either of the following:

rmarkdown::render(input = here::here("text_code/make_script.R"), output_format = "html_document", clean = TRUE)

Or

source(here::here("text_code/make_script.R"), echo = TRUE))
